//
//  SMHMineInviteView.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/6/3.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit

class SMHMineInviteView: LZBaseView {
    
    
    var viewModel : SMHMineViewModel?
    
    override init(viewModel: LZBaseViewModel) {
        super.init(viewModel: viewModel)
        self.viewModel = viewModel as? SMHMineViewModel
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //MARK:setupUI
    func setupUI() {
        
        let rewardImageView = UIImageView.init(image: UIImage.init(named: "icon_mine_reward"))
        addSubview(rewardImageView)
        rewardImageView.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.width.height.equalTo(35)
            make.centerY.equalTo(self.snp.centerY)
        }
        
        let inviteLab = UILabel()
        inviteLab.textColor = UIColorFromHex(rgbValue: 0x363636)
        inviteLab.font = ktextBoldFont(size: 15)
        inviteLab.text = "速卖货，邀请经销商"
        addSubview(inviteLab)
        inviteLab.snp.makeConstraints { (make) in
            make.left.equalTo(rewardImageView.snp.right).offset(6)
            make.width.equalTo(170)
            make.top.equalTo(10)
            make.height.equalTo(16)
            
        }
        
        let inviteDetailLab = UILabel()
        inviteDetailLab.text = "瓜分全年30亿利润"
        inviteDetailLab.textColor = UIColorFromHex(rgbValue: 0x363636)
        inviteDetailLab.font = ktextFont(size: 12)
        addSubview(inviteDetailLab)
        inviteDetailLab.snp.makeConstraints { (make) in
            make.left.equalTo(rewardImageView.snp.right).offset(6)
            make.width.equalTo(170)
            make.top.equalTo(inviteLab.snp.bottom).offset(10)
            make.height.equalTo(12)
             
         }
         
        let inviteBtn = UIButton.init(type: .custom)
        inviteBtn.setTitle("立即邀请", for: .normal)
        inviteBtn.titleLabel?.font = ktextFont(size: 12)
        inviteBtn.setTitleColor(UIColorFromHex(rgbValue: 0x363636), for: .normal)
        addSubview(inviteBtn)
        inviteBtn.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.width.equalTo(70)
            make.height.equalTo(25)
            make.centerY.equalTo(self.snp.centerY)
        }
     
        inviteBtn.borderColor(color: UIColorFromHex(rgbValue: 0x363636))
        inviteBtn.borderWidth(width: 0.5)
        inviteBtn.cornerRadius(cornerRadius: 6)
        
        inviteBtn.reactive.controlEvents(.touchUpInside).observeResult { (button) in
            
            inviteBtn.isSelected = !inviteBtn.isSelected
            if inviteBtn.isSelected {
                       
               UIView.animate(withDuration: 0.3) {
                   rewardImageView.transform =  CGAffineTransform.init(rotationAngle: .pi)
                }
                       
            } else {
                UIView.animate(withDuration: 0.3) {
                                rewardImageView.transform = .identity
                             }
            }
            
            
            print("去邀请 \(button)")
        }
        
        
    }
    
}
